package dt.inlee.common.pagination;

import java.util.LinkedList;
import java.util.List;

import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.LockMode;
import org.hibernate.criterion.DetachedCriteria;

public class SearchBean {

	private boolean cacheAble = true;

	private CacheMode cacheMode = CacheMode.NORMAL;

	private String cacheRegion = null;

	private LockMode lockMode = LockMode.NONE;

	@SuppressWarnings("deprecation")
	private FlushMode flushMode = FlushMode.NEVER;

	private List<ConditionBean> conditions;

	private List<OrderBean> orders;

	private DetachedCriteria detachedCriteria = null;

	public void addCondition(ConditionBean condition) {
		if (this.conditions == null) {
			this.conditions = new LinkedList<ConditionBean>();
		}
		this.conditions.add(condition);
	}

	public void addOrder(OrderBean order) {
		if (this.orders == null) {
			this.orders = new LinkedList<OrderBean>();
		}
		this.orders.add(order);
	}

	public CacheMode getCacheMode() {
		return cacheMode;
	}

	public String getCacheRegion() {
		return cacheRegion;
	}

	public List<ConditionBean> getConditions() {
		return conditions;
	}

	public DetachedCriteria getDetachedCriteria() {
		return detachedCriteria;
	}

	public FlushMode getFlushMode() {
		return flushMode;
	}

	public LockMode getLockMode() {
		return lockMode;
	}

	public List<OrderBean> getOrders() {
		return orders;
	}

	public boolean isCacheAble() {
		return cacheAble;
	}

	public void setCacheAble(boolean cacheable) {
		this.cacheAble = cacheable;
	}

	public void setCacheMode(CacheMode cacheMode) {
		this.cacheMode = cacheMode;
	}

	public void setCacheRegion(String cacheRegion) {
		this.cacheRegion = cacheRegion;
	}

	public void setConditions(List<ConditionBean> conditions) {
		this.conditions = conditions;
	}

	public void setDetachedCriteria(DetachedCriteria detachedCriteria) {
		this.detachedCriteria = detachedCriteria;
	}

	public void setFlushMode(FlushMode flushMode) {
		this.flushMode = flushMode;
	}

	public void setLockMode(LockMode lockMode) {
		this.lockMode = lockMode;
	}

	public void setOrders(List<OrderBean> orders) {
		this.orders = orders;
	}

	public void reset() {
		this.conditions = null;
		this.orders = null;
	}

	public boolean contains() {
		if (this.conditions != null && this.conditions.size() > 0) {
			return true;
		}
		if (this.orders != null && this.orders.size() > 0) {
			return true;
		}
		return false;
	}
}
